﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMaster.Master" AutoEventWireup="true" CodeBehind="User.aspx.cs" Inherits="MonitorPlan.Admin.User" %>
<%@ MasterType VirtualPath="~/Admin/AdminMaster.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>User Management</title>
     <script>
        $(document).ready(function () {
            $("a#btnUser").css("background", "#CCC");
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <%-- sqldatasource for view users --%>
            <asp:SqlDataSource ID="sdUsers" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select * from users where isdeleted=0"></asp:SqlDataSource>

            <%-- Top buttons to view and new user --%>
             <ul class="nav nav-pills action-buttons">
                <li><asp:LinkButton ID="btnView" runat="server" OnClick="btnView_Click">
                    <i class="icon icon-view"></i>&nbsp;View</asp:LinkButton></li>
                 <li>
                     <asp:LinkButton ID="btnAdd" runat="server" OnClick="btnAdd_Click">
                         <i class="icon icon-add"></i>&nbsp;Add New
                     </asp:LinkButton>
                 </li>
            </ul>
            <asp:MultiView ID="mv" runat="server" ActiveViewIndex="0">
                 <%--This is the default view for users--%>
                <asp:View ID="vView" runat="server">
                    <h5 class="text-info">View Users</h5>
                    <asp:Repeater ID="rp1" runat="server" DataSourceID="sdUsers" OnItemCommand="rp1_ItemCommand">
                        <HeaderTemplate>
                             <table class="table table-condensed table-striped table-hover">
                                <tr>
                                    <th>User Id</th>
                                    <th>First Name</th>
                                    <th>Last Name</th>
                                    <th>Gender</th>
                                    <th>Login Name</th>
                                    <th>User Type</th>
                                    <th>Actions</th>
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td><%# Eval("userid") %></td>
                                <td><%# Eval("firstname") %></td>
                                <td><%# Eval("lastname") %></td>
                                <td><%# Eval("gender") %></td>
                                <td><%# Eval("username") %></td>
                                <td><%# Eval("usertype") %></td>
                                <td>
                                    <asp:LinkButton ID="btnDetail" runat="server"
                                        CommandName="detail" CommandArgument='<%# Eval("userid") %>'>
                                        Detail</asp:LinkButton> 
                                     <asp:LinkButton ID="btnEdit" runat="server" 
                                        CommandName="edit" CommandArgument='<%# Eval("userid") %>'>
                                        Edit</asp:LinkButton> 
                                    <asp:LinkButton ID="btnDelete" runat="server"
                                        CommandName="delete" CommandArgument='<%# Eval("userid") %>' OnClientClick="return confirm('You want to delete it?');">
                                        Delete
                                    </asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                    </asp:Repeater>
                </asp:View>
                <%-- view for add new user --%>
                <asp:View ID="vNewUser" runat="server">
                    <h5 class="text-info">Add New User</h5>
                    <label>
                        <asp:TextBox ID="txtFname" runat="server" Width="310" placeholder="First Name"></asp:TextBox>
                        <span class="text-error">*</span>
                    </label>
                    <label>
                        <asp:TextBox ID="txtLname" runat="server" Width="310" placeholder="Last Name"></asp:TextBox>
                    </label>
                    <label>
                        <asp:DropDownList ID="txtGender" runat="server" Width="324">
                            <asp:ListItem>-- Gender --</asp:ListItem>
                            <asp:ListItem Value="M">Male</asp:ListItem>
                            <asp:ListItem Value="F">Female</asp:ListItem>
                        </asp:DropDownList>
                        <span class="text-error">*</span>
                    </label>
                    <label>
                        <asp:TextBox ID="txtAddress" runat="server" Width="310" placeholder="User Address"></asp:TextBox>
                    </label>
                    <label>
                        <asp:TextBox ID="txtUserName" runat="server" Width="310" placeholder="Login Name"></asp:TextBox>
                        <span class="text-error">*</span>
                    </label>
                     <label>
                        <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="310" placeholder="Password"></asp:TextBox>
                        <span class="text-error">*</span>
                     </label>
                     <label>
                        <asp:TextBox ID="txtCPassword" runat="server" Width="310" TextMode="Password"  placeholder="Confirm Password"></asp:TextBox>
                        <span class="text-error">*</span>
                     </label>
                    <label>
                        <asp:DropDownList ID="txtUserType" runat="server" Width="324">
                            <asp:ListItem>-- User Type --</asp:ListItem>
                            <asp:ListItem Value="guest">Guest</asp:ListItem>
                            <asp:ListItem Value="operator">Operator</asp:ListItem>
                            <asp:ListItem Value="admin">Administrator</asp:ListItem>
                        </asp:DropDownList>
                        <span class="text-error">*</span>
                    </label>
                    <%-- action buttons --%>
                    <div class="text-error">* denotes required field.</div>
                     <br />
                    <asp:LinkButton ID="btnSave" runat="server" CssClass="btn btn-primary btn-small" OnClick="btnSave_Click">
                        <i class="icon-ok-circle icon-white"></i> Save</asp:LinkButton>
                    <asp:LinkButton ID="btnCancel" runat="server" CssClass="btn btn-danger btn-small" OnClick="btnCancel_Click">
                        <i class="icon-remove-sign icon-white"></i> Cancel</asp:LinkButton>
                    <asp:LinkButton ID="btnClose" runat="server" CssClass="btn btn-success btn-small" OnClick="btnClose_Click">
                        <i class="icon-arrow-left icon-white"></i> Back</asp:LinkButton>
                    <br /><br />
                    <div runat="server" id="actionSms"></div>
                </asp:View>

                <%-- view for editting user --%>
                <asp:View ID="vUserEdit" runat="server">
                     <h5 class="text-info">Edit User</h5>
                    <asp:HiddenField ID="txtid" runat="server" />
                     <label>
                        <asp:TextBox ID="eTxtFname" runat="server" Width="310" placeholder="First Name"></asp:TextBox>
                        <span class="text-error">*</span>
                    </label>
                    <label>
                        <asp:TextBox ID="eTxtLname" runat="server" Width="310" placeholder="Last Name"></asp:TextBox>
                    </label>
                    <label>
                        <asp:DropDownList ID="eTxtGender" runat="server" Width="324">
                            <asp:ListItem>-- Gender --</asp:ListItem>
                            <asp:ListItem Value="M">Male</asp:ListItem>
                            <asp:ListItem Value="F">Female</asp:ListItem>
                        </asp:DropDownList>
                        <span class="text-error">*</span>
                    </label>
                    <label>
                        <asp:TextBox ID="eTxtAddress" runat="server" Width="310" placeholder="User Address"></asp:TextBox>
                    </label>
                    <label>
                        <asp:TextBox ID="eTxtUserName" runat="server" Width="310" placeholder="Login Name"></asp:TextBox>
                        <span class="text-error">*</span>
                    </label>
                     <label>
                        <asp:TextBox ID="eTxtPassword" runat="server" TextMode="Password" Width="310" placeholder="Password"></asp:TextBox>
                     </label>
                     <label>
                        <asp:TextBox ID="eTxtCPassword" runat="server" Width="310" TextMode="Password"  placeholder="Confirm Password"></asp:TextBox>
                     </label>
                    <label>
                        <asp:DropDownList ID="eTxtUserType" runat="server" Width="324">
                            <asp:ListItem>-- User Type --</asp:ListItem>
                            <asp:ListItem Value="guest">Guest</asp:ListItem>
                            <asp:ListItem Value="operator">Operator</asp:ListItem>
                            <asp:ListItem Value="admin">Administrator</asp:ListItem>
                        </asp:DropDownList>
                        <span class="text-error">*</span>
                    </label>
                    <div class="text-error">* denotes required field.</div>
                     <br />
                    <asp:LinkButton ID="btnUpdate" runat="server" CssClass="btn btn-primary btn-small" OnClientClick="return confirm('You want to update?')" OnClick="btnUpdate_Click">
                        <i class="icon-ok-circle icon-white"></i> Update</asp:LinkButton>
                    <asp:LinkButton ID="btnCancelUpdate" runat="server" CssClass="btn btn-danger btn-small" OnClick="btnCancelUpdate_Click">
                        <i class="icon-remove-sign icon-white"></i> Cancel</asp:LinkButton>
                    <div id="updateSms" runat="server"></div>
                </asp:View>
                <%-- View detail information of each user --%>

                <asp:View ID="vUserDetail" runat="server">
                    <h5 class="text-info">User Information</h5>
                     <table class="tbl">
                      <tr>
                          <th>User Id</th>
                          <td style="width: 40px;">&nbsp;:</td>
                          <td><asp:Label ID="lbUserId" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <th>First Name</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbFname" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <th>Last Name</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbLname" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                       <tr>
                          <th>Gender</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbGender" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                       <tr>
                          <th>Address</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbAddress" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <th>Login Name</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbUserName" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <th>User Type</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbUserType" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <th>Is Deleted</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbIsDeleted" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <td></td>
                          <td></td>
                          <td></td>
                      </tr>
                      <tr>
                          <td>
                              <asp:LinkButton ID="btnBack" runat="server" CssClass="btn btn-success btn-small" OnClick="btnBack_Click">
                                  <i class="icon-arrow-left icon-white"></i> Back</asp:LinkButton>
                          </td>
                          <td></td>
                          <td></td>
                      </tr>
                  </table>
                </asp:View>
            </asp:MultiView>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
